package leetcode;

public class twentyfour {
    public static int takeAttendance(int[] records) {
//        int sum=((records[0]+records[records.length-1])*(records[records.length-1]+1))/2;
//        int ret=0;
//        for(int i=0;i<records.length;i++){
//            ret=ret+records[i];
//        }
//        return  sum-ret;

        //二分查找法解决
        if(records.length==1){
            if(records[0]==1){
                return 0;
            }
            if(records[0]==0){
                return 1;
            }
        }
        int left=0;
        int right=records.length-1;
        while(left<right){
            int mid=left+(right-left)/2;
            if(records[mid]==mid){
                left=mid+1;
            }else{
                right=mid;
            }
        }
//        if(records[left]==left){
//            return left+1;
//        }
        return records[left]==left?left+1:left;





    }

    public static void main(String[] args) {
        int[] arr={0,1};
        int i = takeAttendance(arr);
        System.out.println(i);

    }
}
